﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LambdaList
{
    public class Program
    {
        static void Main(string[] args)
        {
            List<Employee> lstEmp = new List<Employee>();

            lstEmp.Add(new Employee() { Name = "章三", Sex = "M", Age = 21 });

            lstEmp.Add(new Employee() { Name = "熊四", Sex = "W", Age = 19 });

            lstEmp.Add(new Employee() { Name = "王无", Sex = "M", Age = 20 });

            lstEmp.Add(new Employee() { Name = "胡总", Sex = "W", Age = 32 });


            //List<Employee> employees = lstEmp.Where(c => c.Name == "章三").ToList(); //查询姓名为章三的信息

            //List<Employee> employees = lstEmp.Where(c => c.Age > 20).ToList(); //查找年龄大于20的信息

            //foreach (var item in employees)
            //{
            //    Console.WriteLine("姓名 = " + item.Name + " 性别 = " + item.Sex + " 年龄 = " + item.Age);

            //}

            //Employee empl = lstEmp.Where(c => c.Sex == "W" && c.Age >= 19).FirstOrDefault(); //查询性别为W并且年龄大于等于19的信息

            //Console.WriteLine("姓名 = " + empl.Name + " 性别 = " + empl.Sex + " 年龄 = " + empl.Age);



            //List<Employee> employees = lstEmp.Select(p => p).ToList(); //获取所有            
            //List<Employee> employees = lstEmp.OrderByDescending(s => s.Age).ToList(); //排序            

            //List<Employee> employees = lstEmp.Where(s => (s.Age == 18 || s.Name=="章三") ).ToList(); //筛选

            //foreach (var item in employees)
            //{
            //    Console.WriteLine("姓名 = " + item.Name + " 性别 = " + item.Sex + " 年龄 = " + item.Age);

            //}


            string empName = lstEmp.Where(c => c.Sex == "M" && c.Age > 20).Select(c => c.Name).FirstOrDefault(); //查询性别为M，年龄大于20的姓名
            Console.WriteLine("姓名 = " + empName);

            Console.ReadLine();
        }
    }
}
